package com.baofu.paycore.mock;

import com.baofu.account.service.facade.TransferService;
import com.baofu.paycore.service.facade.model.PayBaseDTO;
import lombok.extern.slf4j.Slf4j;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.stereotype.Component;
import org.springframework.test.util.ReflectionTestUtils;

/**
 * mock
 *
 * @author LZQ
 * @version 1.0.0 createTime: 15/1/12 上午10:53
 */
@Slf4j
@Component
public  class MockUtils {

//    @Mock
//    private BankService bankService;
    @Mock
    private TransferService transferServiceImpl;

    /**
     * mock 初始化
     */
    public void mockInit(PayBaseDTO payBaseDTO,Object...target) {
        try {
            MockitoAnnotations.initMocks(this);
            for(int i = 0; i < target.length; i ++){
                ReflectionTestUtils.setField(AopTargetUtils.getTarget(target[i]), "transferService", transferServiceImpl);
            }
//            ReflectionTestUtils.setField(AopTargetUtils.getTarget(handlerHelper), "transferService", transferService);
//            doReturn(createWebResponse()).when(bankService).webPay(any(FundProcBillDO.class), any(AbstractFundInfo.class), any(MainPayDO.class));
//            doReturn(createBankPayResponse(payBaseDTO)).when(bankService).pay(any(FundProcBillDO.class), any(AbstractFundInfo.class), any(MainPayDO.class));
//            doReturn(createBankPayResponse(payBaseDTO)).when(handlerHelper).driveBankFund(any(PayBO.class),anyInt());
//            doCallRealMethod().when(bankService).pay(any(FundProcBillDO.class), any(AbstractFundInfo.class), anyString());
        } catch (Exception e) {
            log.error("mockInit 错误：{}",e);
        }
    }

    /**
     * 组装 bank 处理返回参数
     *
     * @return bank 处理响应
     */
//    private BankResponse  createBankResponse() {
//        BankResponse bankResponse = new BankResponse();
//        bankResponse.setTranStatus("B");
//        bankResponse.setTranAmt(1L);
//        //bankResponse.setTranReqNo("201501151357");
//        bankResponse.setRespCode("S");
//        bankResponse.setRespDesc("S");
//        bankResponse.setOuterTranNo("11111111122");
//        bankResponse.setOuterTranDate(DateUtil.getCurrentDate());
//        bankResponse.setRealFlag(true);
//        return bankResponse;
//    }


//    public FundProcBillDO findFundBill(PayBaseDTO payBaseDTO){
////        List<MainPayDO> mainPayDO = mainPayMapper.validateOrderPayAgain(payBaseDTO.getRequestSystem(), payBaseDTO.getRequestBizNo(), payBaseDTO.getRequestUser(), payBaseDTO.get());
//        List<FundProcBillDO> fundProcBillDOs = fundProcBillManager.selectByPayNo(mainPayDO.get(0).getPayNo());
//        return fundProcBillDOs.get(0);
//    }
}
